<?php
require_once(APPPATH.'libraries/infoobject.php');

/**
 * Info Model
 */
class Info_Model extends CI_Model {
	
	function __construct()
	{
		parent::__construct();
	}
	
	public function getInfo()
	{
		$inf = new InfoObject();
		
		$data = $this->db->get(INFO_TABLE);
		
		if ($data->num_rows() > 0)
		{
			$row = $data->row();
			$inf->setInfo($row->info);
			$inf->setId($row->id);
		}
		
		return $inf;
	}
	
	public function updateInfo($id, $info)
	{
		$query = "UPDATE ".INFO_TABLE." SET info=? WHERE id=?";
		
		$this->db->trans_start();
		$this->db->query($query, array($info->getInfo(), $id));
		$this->db->trans_complete();
		
		if ($this->db->trans_status() === FALSE)
			return UPDATE_ERROR;
		return ERROR_NONE;
	}
	
	public function insertInfo($info)
	{
		$data = array(	"id"	=> NULL,
						"info"	=> $info->getInfo());
		$this->db->trans_start();
		$this->db->insert(INFO_TABLE, $data);
		$this->db->trans_complete();
		
		if ($this->db->trans_status() === FALSE)
			return INSERT_ERROR;
		return ERROR_NONE;
	}
}


?>